package com.fingard.dsp.bank.reqrespobj.unifiedorder;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.text.StringHelper;
import com.fingard.xml.XmlTextReader;

public class ReqQueryOrder extends RequestBase{

	/**公众账号ID*/
	public String appId = "";
	
	/**本方账号*/
	public String ownAct = "";
	
	/**商户号*/
	public String merchantId = "";

    /**是否为移动端*/
    public String isMobile = "";


    /**商户定义的商品id 或者订单号*/
	public String rdSeq;
	
	/**外部订单号*/
	public String outTransID;
	
	public String bgnDate;
	public Date getBgnDateTime() throws ParseException{
		if(StringHelper.hasAnyChar(bgnDate)){
			if(bgnDate.length()==14){
				return Format.DateTime14Format.parse(bgnDate);
			}
			else{
				return Format.DateTimeFormat.parse(bgnDate);
			}
		}
		return null;
	}
	public String payState;
	
	public ReqQueryOrder(HashMap<String,String> p_hashMap, ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
		if(p_hashMap.containsKey("AppId")){
			appId = p_hashMap.get("AppId");
			if(appId == null){
				appId = "";
			}
		}
		if(p_hashMap.containsKey("OurBankAccount")){
			ownAct = p_hashMap.get("OurBankAccount");
			if(ownAct == null){
				ownAct = "";
			}
		}
		if(p_hashMap.containsKey("MchId")){
			merchantId = p_hashMap.get("MchId");
			if(merchantId == null){
				merchantId = "";
			}
		}
		if(p_hashMap.containsKey("RdSeq")){
			rdSeq = p_hashMap.get("RdSeq");
		}
		if(p_hashMap.containsKey("OutTransID")){
			outTransID = p_hashMap.get("OutTransID");
		}
		
		if(p_hashMap.containsKey("BgnDate")){
			bgnDate = p_hashMap.get("BgnDate");
		}

		else if(p_hashMap.containsKey("PaySentDate")){//PaySentDate
			bgnDate = p_hashMap.get("PaySentDate");
		}
		if(p_hashMap.containsKey("PayState")){
			payState = p_hashMap.get("PayState");
		}
		if(StringHelper.isNullOrEmpty(payState)){
			payState = "5";
		}

        if(p_hashMap.containsKey("IsMobile")){
            isMobile = p_hashMap.get("IsMobile");
        }

		
	}
	public ReqQueryOrder(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
		//XmlTextReader xmlReader = p_xmlReader;
		if(p_xmlReader.read(PATH_Detail)){//"/ATSYH/TransReq/TransParam/DetailRecord"
			appId = p_xmlReader.readedXElement.getSingleText("AppId"); 
			bgnDate = p_xmlReader.readedXElement.getSingleText("BgnDate");
			if(StringHelper.isNullOrEmpty(bgnDate)){
				bgnDate = p_xmlReader.readedXElement.getSingleText("PaySentDate");
			}
			ownAct = p_xmlReader.readedXElement.getSingleText("OurBankAccount");
			merchantId = p_xmlReader.readedXElement.getSingleText("MchId");
			rdSeq = p_xmlReader.readedXElement.getSingleText("RdSeq");
			
			payState = p_xmlReader.readedXElement.getSingleText("PayState");
			if(StringHelper.isNullOrEmpty(payState)){
				payState = "5";
			}
		}
		else{
			throw new Exception("不存在节点："+PATH_Detail);
		}
	}
}
